package com.xiaobu.shop.config;


import com.xiaobu.shop.domain.ResponseResult;
import com.xiaobu.shop.domain.exception.ShopException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class ExceptionConfig {

    /**
     * 全局捕获异常
     * @param e
     * @return
     */
    @ExceptionHandler(ShopException.class)
    public ResponseResult<?> ShopExceptionHandler(ShopException e){
        log.error("ERROR:"+e.getMessage());
        ResponseResult responseResult = new ResponseResult(e.code,e.getMessage());
        return responseResult;
    }
}
